package com.example.common;

import com.example.commonlib.base.model.SuperModel;
import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry;
import ohos.app.Context;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.util.HashSet;
import java.util.Set;

import static org.junit.Assert.*;

public class SuperModelTest {

    private final Context mContext = AbilityDelegatorRegistry.getAbilityDelegator().getAppContext();

    private SuperModel superModel;

    private static String key = "key";

    @Before
    public void setUp() throws Exception {
        SuperModel.initialize(mContext);
        superModel = new SuperModel();
    }

    @After
    public void tearDown() throws Exception {
    }

    @Test
    public void putInt() {
        superModel.putInt(key, 1);
        int num = superModel.getInt(key, 1);
        assertEquals(1, num);
    }

    @Test
    public void putFloat() {
        superModel.putFloat(key, 1f);
        int num = (int) superModel.getFloat(key, 1f);
        assertEquals(1, num);
    }

    @Test
    public void putLong() {
        superModel.putLong(key, 1L);
        long num = superModel.getLong(key, 1L);
        assertEquals(1, num);
    }

    @Test
    public void putString() {
        superModel.putString(key, "1");
        String str = superModel.getString(key, "1");
        assertEquals("1", str);
    }

    @Test
    public void putBoolean() {
        superModel.putBoolean(key, true);
        boolean state = superModel.getBooolean(key, true);
        assertTrue(state);
    }

    @Test
    public void setStringSet() {
        Set<String> s = new HashSet<String>();
        superModel.setStringSet(key, s);
        Set<String> str = superModel.getStringSet(key, s);
        assertSame(s, str);
    }
}